<?PHP
/*
 * Copyright 2008 by Oliver Radwan, Maxwell Palmer, Nolan McNair,
 * Taylor Talmage, and Allen Tucker.  This program is part of RMH Homebase.
 * RMH Homebase is free software.  It comes with absolutely no warranty.
 * You can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation
 * (see <http://www.gnu.org/licenses/ for more information).
*/
/*
 *	personForm.inc
 *  shows a form for a person to be added or edited in the database
 *	@author Oliver Radwan and Allen Tucker
 *	@version 9/1/2008
 */

if ($_SESSION['access_level']==0) {
    echo('<strong>New Volunteer Application Form</strong><br />');
	echo('Please provide us with some basic information about yourself and your interests.' .
		 '<br>When you are finished, hit <b>Submit</b> at the bottom of this page.');
}
else if($_SESSION['access_level']==1)
    if ($_SESSION['_id']!=$person->get_id()){
		echo("<p id=\"error\">You do not have sufficient permissions to edit this user.</p>");
		include('footer.inc');
		echo('</div></div></body></html>');
		die();
	}
	else {
		echo('<strong>Personnel Edit Form</strong><br />');
	    echo('Here you can edit your own information in the database.' .
	    	 '<br>When you are finished, hit <b>Submit</b> at the bottom of this page.');
	}
else if ($_SESSION['access_level']==2)
	if ($id=='new') {
	  echo('<strong>Personnel Input Form</strong><br />');
	  echo('Here you can add a new volunteer into the database. (On this form, "you" means the new person being added.)</p>');
    }
    else {
	   echo('<strong>Personnel Edit Form</strong><br />');
	   echo('Here you can edit, delete, or change the password for a volunteer in the database.</p><p>');
    }
else {
    echo("<p id=\"error\">You do not have sufficient permissions to add a new person to the database.</p>");
	include('footer.inc');
	echo('</div></div></body></html>');
	die();
}

?>
<form method="POST">
	<input type="hidden" name="old_id" value=<?PHP echo("\"".$id."\"");?>>
	<input type="hidden" name="old_pass" value=<?PHP echo("\"".$person->get_password()."\"");?>>
	<input type="hidden" name="_form_submit" value="1">
<p><span style="font-size:x-small;color:FF0000">*</span> denotes required fields
	<span class="bigTable">
	<table>
		<tr><td>First Name<span style="font-size:x-small;color:FF0000">*</span>:</td><td> <input type="text" name="first_name" tabindex=1 value="<?PHP echo($person->get_first_name())?>"></td></tr>
		<tr><td>Last Name<span style="font-size:x-small;color:FF0000">*</span>:</td><td> <input type="text" name="last_name" tabindex=2 value="<?PHP echo($person->get_last_name())?>"></td></tr>
		<tr><td>Address<span style="font-size:x-small;color:FF0000">*</span>:</td><td> <input type="text" name="address" tabindex=3 value="<?PHP echo($person->get_address())?>"></td></tr>
		<tr><td>City<span style="font-size:x-small;color:FF0000">*</span>:</td><td> <input type="text" name="city" tabindex=4 value="<?PHP echo($person->get_city())?>"></td></tr>
		<tr><td>State, Zip<span style="font-size:x-small;color:FF0000">*</span>:</td>
		<td><select name="state" tabindex=5>
		<?PHP

			$states = array("AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN","IA",
					        "KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM",
					        "NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA",
					        "WV","WI","WY");
			foreach ($states as $st) {
				echo "<option value='" . $st . "' ";
                if($person->get_state() == $st ) echo("SELECTED");
                else if ($id == "new" && $st =="DE") echo("SELECTED");
                echo ">" . $st . "</option>";
			}
		?>
		</select>,
		<input type="text" name="zip" size="5" tabindex=6 value="<?PHP echo($person->get_zip())?>"></td></tr>
		<tr><td>Primary Phone<span style="font-size:x-small;color:FF0000">*</span>:</td><td> <input type="text" name="phone1" MAXLENGTH=12 tabindex=7 value="<?PHP echo($person->get_phone1())?>"></td></tr>
		<tr><td>Alternate Phone:</td><td><input type="text" name="phone2" MAXLENGTH=12 tabindex=8 value="<?PHP echo($person->get_phone2())?>"></td></tr>
		<tr><td>Email:</td><td><input type="text" name="email" tabindex=9 value="<?PHP echo($person->get_email())?>"></td></tr>


       <tr><td>Birthday:</td><td>
<?PHP
		echo('<select name="DateOfBirth_Month">');
		echo('<option value=""></option>');
        $months = array('','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
        for ($i = 1; $i <= 12; $i++) {
            if ($i < 10) {
            	echo '<option value=0'.$i;
            	if (substr($person->get_birthday(),1,1)==="$i") echo(' SELECTED');
            	echo '>' . $months[$i] . ' </option>';
            }
            else {
            	echo '<option value='.$i;
            	if (substr($person->get_birthday(),0,2)==="$i") echo(' SELECTED');
            	echo '>' . $months[$i] . ' </option>';
            }
        }
?>

		</select>

		<select name="DateOfBirth_Day">
		<option value=""></option>
<?PHP
         for ($i = 1; $i <= 31; $i++) {
            	if ($i < 10)
            	   { echo '<option value=0'.$i; if(substr($person->get_birthday(),4,1)==="$i") echo(' SELECTED'); echo '>' . $i . ' </option>'; }
                else
                   { echo '<option value='.$i; if(substr($person->get_birthday(),3,2)==="$i") echo(' SELECTED'); echo '>' . $i . ' </option>'; }
            }
?>

		</select>

		<select name="DateOfBirth_Year">
		<option value=""></option>
<?PHP
		$start_year = date("Y");
        for ($i = $start_year; $i >= ($start_year-80); $i--){
         	    if ($i > 1999 && $i < 2010)
            	   { echo '<option value=0'.substr($i,3,1); if(substr($person->get_birthday(),7,1)===substr($i,3,1)) echo(' SELECTED'); echo '>' . $i . ' </option>'; }
                else
                   { echo '<option value='.substr($i,2,2); if(substr($person->get_birthday(),6,2)===substr($i,2,2)) echo(' SELECTED'); echo '>' . $i . ' </option>'; }
            }
?>
		</select>
        </td></tr>


	    <tr><td>Volunteer Start Date:</td><td>
		<select name="DateOfStart_Month">
		<option value=""></option>
<?PHP
           $months = array('','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
           for ($i = 1; $i <= 12; $i++) {
           	    if ($i < 10)
            	   { echo '<option value=0'.$i; if(substr($person->get_start_date(),0,2)==="0"."$i") echo(' SELECTED'); echo '>' . $months[$i] . ' </option>'; }
                else
                   { echo '<option value='.$i; if(substr($person->get_start_date(),0,2)==="$i") echo(' SELECTED'); echo '>' . $months[$i] . ' </option>'; }
            }
?>
		</select>
        <select name="DateOfStart_Day">
		<option value=""></option>
<?PHP
         for ($i = 1; $i <= 31; $i++) {
            	if ($i < 10)
            	   { echo '<option value=0'.$i; if(substr($person->get_start_date(),3,2)==="0"."$i") echo(' SELECTED'); echo '>' . $i . ' </option>'; }
                else
                   { echo '<option value='.$i; if(substr($person->get_start_date(),3,2)==="$i") echo(' SELECTED'); echo '>' . $i . ' </option>'; }
            }
?>
		</select>
        <select name="DateOfStart_Year">
		<option value=""></option>
<?PHP
        $start_year = date("Y");
        for ($i = $start_year; $i >= ($start_year-80); $i--){
            	if ($i > 1999 && $i < 2010)
            	   { echo '<option value=0'.substr($i,3,1); if(substr($person->get_start_date(),7,1)===substr($i,3,1)) echo(' SELECTED'); echo '>' . $i . ' </option>'; }
                else
                   { echo '<option value='.substr($i,2,2); if(substr($person->get_start_date(),6,2)===substr($i,2,2)) echo(' SELECTED'); echo '>' . $i . ' </option>'; }
            }
?>
		</select>
		</td></tr>
</table>
</span>
<?PHP
    $st = implode(',',$person->get_type());
    $newpersontypes = array('App'=>'Not sure', 'Rec'=>'House reception (3 hour shift weekly or bi-weekly)',
					'Fam'=>'House family room (3 hour shift)',
                   	'Van'=>'Van Driver (you must be 21 years or older and trained)',
					'Kit'=>'Kitchen help',
					'Off'=>'Office work',
                   	'Lin'=>'Linens',
					'Chr'=>'Christiana Neonatal Care family room',
					'Dup'=>'duPont Hospital family room');
    $types = array('App'=>'Applicant', 'Rec'=>'House reception', 'Fam'=>'House family room',
                   'Van'=>'Van Driver', 'Kit'=>'Kitchen help', 'Off'=>'Office work',
                   'Lin'=>'Linens', 'Chr'=>'Christiana Neonatal Care family room', 'Dup'=>'duPont Hospital family room',
                   'trainee'=>'trainee', 'teen'=>'teen', 'sub'=>'sub', 'committee'=>'committee', 'manager'=>'manager'
                   );
    if ($_SESSION['access_level']==0) {
	     echo('<p>Please check below all position types for which you are applying:');
	     $ts = $newpersontypes;
    }
	else {
		 echo('<p>Position types for this person:');
		 $ts = $types;
	}
	echo('<span style="font-size:x-small;color:FF0000">*</span><br>');

    foreach ($ts as $key=>$value) {
    	echo ('<input type="checkbox" name="type[]" value=' . $key);
    	if (strpos($st,$key)!==false) echo(' CHECKED');
    	echo ('>' . $value . '<br />');
    }
    echo ('<p><strong>Status: </strong>');
    echo('<select name="status">');
    echo ('<option value=""></option>');
    echo ('<option value="active"');if ($person->get_status()=='active') echo (' SELECTED'); echo('>active</option>');
//	echo ('<option value="teen"');if ($person->get_status()=='teen') echo (' SELECTED'); echo('>teen</option>');
//	echo ('<option value="trainee"');if ($person->get_status()=='trainee') echo (' SELECTED'); echo('>trainee</option>');
	echo ('<option value="LOA"');if ($person->get_status()=='LOA') echo (' SELECTED'); echo('>LOA</option>');
	echo ('<option value="former"');if ($person->get_status()=='former') echo (' SELECTED'); echo('>former</option>');
//	echo ('<option value="committee"');if ($person->get_status()=='committee') echo (' SELECTED'); echo('>committee</option>');
//	echo ('<option value="sub"');if ($person->get_status()=='sub') echo (' SELECTED'); echo('>sub</option>');
	echo('</select>');
?>
</p>
<p><strong>Availability<span style="font-size:x-small;color:FF0000">*</span> </strong> (required for all volunteer positions)
				<span class="bigTable">
				<table>
					<tr>
					<td></td><td>Monday</td><td>Tuesday</td><td>Wednesday</td><td>Thursday</td><td>Friday&nbsp;&nbsp;&nbsp;</td><td>Saturday</td><td>Sunday</td></tr>
<?PHP
    $shifts = array('9-12'=>'3 hours morning<br />(9-12 or 10-1)', '12-15'=>'3 hours early afternoon<br />(12-3 or 1-4)', '15-18'=>'3 hours late afternoon<br />(3-6, 4-7, or 2-5)',
                    '18-21'=>'3 hours evening<br />(6-9 or 5-9)');
    $days = array('Mon', 'Tue', 'Wed' , 'Thu', 'Fri', 'Sat', 'Sun');
    $person_availability = implode(',',$person->get_availability());
    foreach ($shifts as $shiftkey => $shiftvalue) {
       echo ('<tr><td>'. $shiftvalue .'</td>');
       foreach ($days as $day) {
       	  $realkey = $day . $shiftkey;
       	  echo ('<td><input type="checkbox" name="availability[]" value=' . $realkey);
    	  if (strpos($person_availability,$realkey)!==false) echo(' CHECKED');
    	  echo ('></td>');
       }
       echo ('</tr>');
    }
?>
</table>
</span></p>
<p>
		<?PHP
		if($id == 'new' || strpos(implode(',',$person->get_type()),'applicant') !== false) {
		  echo('<p>Why are you interested in volunteering at the Ronald McDonald House (RMH)?<br />');
	      echo('<textarea name="motivation" rows="3" cols="60">');
	      echo($person->get_motivation());
	      echo('</textarea>');

	      echo('<p>Do you have any special talents, interests, or skills you would like to bring to RMH?<br />');
	      echo('<textarea name="specialties" rows="3" cols="60">');
	      echo($person->get_specialties());
	      echo('</textarea>');

	      echo('<p>Employer:<br />');
	      echo('<textarea name="employer" rows="1" cols="60">');
	      echo($person->get_occupation());
	      echo('</textarea>');
          
	      echo('<p>Please list up to two references and their phone numbers, whom we may contact.<br />');
	      echo('<textarea name="references" rows="2" cols="60">');
	      echo($person->get_references());
	      echo('</textarea>');
	      
          echo('<p>What else would you like us to know about you?<br />');
	      echo('<textarea name="notes" rows="3" cols="60">');
	      echo($_POST['notes']);
	      echo('</textarea>');
		}
/*		if($_SESSION['access_level']>=2){
			if (strpos(implode(',',$person->get_type()),'applicant') !== false) {
					echo('<p> <strong>Applicant Status</strong><table>' .
				   		' <tr><td><input type="checkbox" name="background_check" value="yes" ');
					if($person->get_background_check()=='yes')
						echo("CHECKED");
					echo ('></td>');
					echo ('<td>Background Check Cleared</td></tr>' .
						' <tr><td><input type="checkbox" name="interview" value="yes" ');
					if($person->get_interview()=='yes')
						echo("CHECKED");
					echo('></td><td>Interview Completed</td></tr>' .
						' <tr><td><input type="checkbox" name="shadow" value="yes"  ');
					if($person->get_shadow()=='yes') echo("CHECKED");
					echo('></td><td>Shadow Completed</td></tr></table> ');
			}
		}
		*/
		else if ($_SESSION['access_level']>=1) {
	  	    		echo('<p><strong>Notes</strong> - notes between the House Manager and the volunteer. <br />');
	  	    		echo('<textarea name="notes" rows="3" cols="60"');
	  	    		if($_SESSION['access_level']==1)
	  	    			echo(' disabled="true"');
	  	    		echo('>'. $person->get_notes() . '</textarea>');
		}

		  echo('<input type="hidden" name="schedule" value="'.implode(',',$person->get_schedule()).'">');
		  echo('<input type="hidden" name="history" value="'.implode(',',$person->get_history()).'">');
		  echo('<input type="hidden" name="password" value="'.$person->get_password().')">');
		  echo('<input type="hidden" name="_submit_check" value="1"><p>');
		  if ($_SESSION['access_level']==0)
		  	 echo('Hit <input type="submit" value="Submit" name="Submit Edits"> to complete this application.<br /><br />');
		  else
		     echo('Hit <input type="submit" value="Submit" name="Submit Edits"> to submit these edits.<br /><br />');
		  if ($id != 'new' && $_SESSION['access_level']>=2) {
			echo ('<input type="checkbox" name="deleteMe" value="DELETE"> Check this box and then hit ' .
				'<input type="submit" value="Delete" name="Delete Entry"> to delete this entry. <br />' .
				'<input type="checkbox" name="reset_pass" value="RESET"> Check this box and then hit ' .
				'<input type="submit" value="Reset Password" name="Reset Password"> to reset this user\'s password.</p>');
		}
		?>
</form>
